# -*- coding: utf-8 -*-
import json

def getPersonCertList(request):

    #1数据
    request.cursor_standard.execute(request.formatSql('''
        select * 
        from middle.person_apt_${data_source_code} as person_cert
        left join dict_person_apt on person_cert.cert_dict_id = dict_person_apt.cert_dict_id
        left join dict_person_apt_level c on person_cert.level_id = c.level_id
        where person_id like '%${person_id}%'
        and ('${cert_dict_id}' = '' or person_cert.cert_dict_id = '${cert_dict_id}')
        limit ${start} , ${rows}
    '''))
    rows = request.cursor_standard.fetchall()
    #2页码
    request.cursor_standard.execute(request.formatSql('''
        select count(*)  as total
        from middle.person_apt_${data_source_code} as person_cert
        where person_id like '%${person_id}%'
        and ('${cert_dict_id}' = '' or cert_dict_id = '${cert_dict_id}')
    '''))
    total = request.cursor_standard.fetchone()['total']
    return json.dumps({'rows':rows,'total':total}, ensure_ascii=False)